package com.wx.frame.serviceimpl;

import com.wx.frame.mapper.LogMapper;
import com.wx.frame.service.LogService;
import com.wx.utils.Page;
import com.wx.utils.Pageable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by myd on 16/3/4.
 */
@Service("logServiceImpl")
public class LogServiceImpl<Log> implements LogService<Log> {

    /**
     * 注入
     */
    @Autowired
    private LogMapper<Log> logMapper;

    /**
     * 获取所有的数据
     * 支持条件查询
     */
    @Override
    public List<Log> getAll(Log entity) {
        return this.logMapper.getall(entity);
    }

    /**
     * 分页获取数据
     * 支持条件查询
     */
    @Override
    public Page<Log> findPage(Pageable pageable, Log entity) {
        Map<String,Object> map=new HashMap();
        map.put("pageable",pageable);
        map.put("roles",entity);
        List<Log> list=this.getAll(entity);
        List<Log> entitys=this.logMapper.findpage(map);
        Page<Log> page=new Page<>();
        page.setRows(entitys);
        page.setTotalCount(entitys.size());
        page.setPage(pageable.getPage());
        page.setTotal(list.size());
        return page;
    }

    /**
     * 保存数据
     * @param entity
     * @return
     */
    @Override
    public int save(Log entity) {
        return this.logMapper.save(entity);
    }

    /**
     * 批量删除数据
     * @param idList 主键集合
     * @return
     */
    @Override
    public int delete(List<String> idList) {
        return this.logMapper.delete(idList);
    }
}